<?php  

	global $pf_lb_settings;
    $pf_lb_settings = array(
      'show_helper_text' => "",     
      'show_info' => "",    
      'show_extended_info' => "",   
      'download_link' => "false",
      'auto_resize' => "",    
      'colorBlend' => "",
      'show_linkback' => "",
      'auto_scroll' => "",
      'speed' => "",
      'opacity' => "",
      'padding' => "",
      'rel' => "",
      'auto_relify' => "",
    );
	
	function pf_lb_load_settings()
    {	
		global $pf_lb_settings;
		$data = cv_get_option();        
		 
		$pf_lb_settings['show_helper_text'] = ($data['pf_enable_show_helper'] == true)?"":"false";
		$pf_lb_settings['show_info'] = ($data['pf_show_info'] == "Always show")?"true":"";
		$pf_lb_settings['show_extended_info'] = ($data['pf_show_info'] == "Always show")?"true":"";
		$pf_lb_settings['speed'] = $data['pf_speed'];
		$pf_lb_settings['opacity'] = $data['pf_opacity'];
			
    }
    
	add_action( 'wp_print_scripts', 'pf_lb_load_jquery' );
	function pf_lb_load_jquery()
    {	
		if ( !is_page_template('page-portfolio.php') )  return; 
		 
		$path = trailingslashit(CVINCLUDES_PORTFOLIO_URI) . 'scripts/';      
		  
		wp_enqueue_script('jquery-lightbox', $path.'jquery.lightbox.min.js', array('jquery'));
		wp_enqueue_script('jquery-lightbox-function', $path.'jquery.lightbox.function.min.js', array('jquery', 'jquery-lightbox'));
		  
		add_filter('attachment_link', 'pf_lb_fixLink');	  
    }
    
	add_action('wp_head', 'pf_lb_wp_head');	
    function pf_lb_wp_head()
    {
	  if ( is_admin() )  return; 
	 
	  global $pf_lb_settings;
	  
      $has_output = false;
      ?>      
		<script type="text/javascript">jQuery(function($) {
			$.Lightbox.construct({
			<?php
			  foreach ($pf_lb_settings as $setting_id => $setting_value)
			  {
				if ($setting_value != "")
				{
				  if ($has_output) echo ", ";
				  
				  if ($setting_value != "true" && $setting_value != "false")
					$setting_value = "\"$setting_value\"";
				  
				  echo "\"$setting_id\": $setting_value";
				  
				  $has_output = true;
				}
			  }?>
			});
		});</script>
     <?php
    }   
    
    function pf_lb_fixLink()
    {
      $post = get_post($id);
      
      if (substr($post->post_mime_type, 0, 6) == 'image/')
        return wp_get_attachment_url($id);
      else
        return $link;
    }    
	
	
	pf_lb_load_settings();
    

?>